package com.kreig133.spine.simplemodel;

import com.kreig133.spine.abstractmodel.AbstractAlgorithm;
import com.kreig133.spine.abstractmodel.AbstractSpine;
import com.kreig133.spine.abstractmodel.AbstractVelebra;

/**
 *
 * @author C.C.-fag
 */
public class SimpleVelebra extends AbstractVelebra {

    private double koeff = 1;
    
    public SimpleVelebra(AbstractAlgorithm alg, AbstractSpine spine) {
        super(alg, spine);
        this.state = new SimpleState();
        alg.setVelebra(this);
    }

    @Override
    public void nextState() {
        state = algorithm.calculate(spine.getEnvironment(this), state);
    }

    /**
	 * 
	 * @return 
	 */
	@Override
	@SuppressWarnings({"static-access", "CallToThreadDumpStack"})
    public void run() {
//        Thread.currentThread().setDaemon(true);

        while (true) {
            synchronized (spine.forSynchronize) {
                spine.addState(this, state);
                try {
                    spine.forSynchronize.wait();
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
                nextState();
            }
        }
    }
    
    public void setPosition(Double newPosition){
        this.state.setCoordinate(newPosition);
    }
    
    public void setKoeff(Double koeff){
        this.koeff = koeff;
    }
    
}
